package com.zenchn.service.impl;

import com.zenchn.dao.TMiRegionMapper;
import com.zenchn.dynamic.TMiRegionDynamicMapper;
import com.zenchn.generic.GenericDao;
import com.zenchn.generic.GenericServiceImpl;
import com.zenchn.model.TMiRegion;
import com.zenchn.model.TMiRegionExample;
import com.zenchn.service.RegionService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * 区域信息Service实现类
 *
 * @author dingxinfa
 * @date 2020-04-16
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class RegionServiceImpl extends GenericServiceImpl<TMiRegion, String, TMiRegionExample> implements RegionService {

    @Resource
    private TMiRegionMapper regionMapper;

    @Resource
    private TMiRegionDynamicMapper regionDynamicMapper;

    @Override
    public GenericDao<TMiRegion, String, TMiRegionExample> getDao() {
        return regionMapper;
    }

    @Override
    public Boolean verifyRegionName(String regionId, String regionName) {

        TMiRegionExample regionExample = new TMiRegionExample();
        TMiRegionExample.Criteria criteria = regionExample.createCriteria();
        criteria.andRegionNameEqualTo(regionName);
        if (null != regionId && !"".equals(regionId.trim())) {
            criteria.andRegionIdNotEqualTo(regionId);
        }

        return regionMapper.countByExample(regionExample) <= 0;
    }
}
